
import com.bjmashibing.system.huawei.vivo.vivo_push;
import com.bjmashibing.system.test_xiaomi;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @Classname vivo_test
 * @Description TODO
 * @Date 2020/12/15/015 16:42
 * @Created by Administrator
 */
public class vivo_test {
    private final static Logger logger = LoggerFactory.getLogger(vivo_test.class);
    @Test
    public void test() {
        logger.info("dddddddddddd");





        /*try {
            Map<String, String> map = new HashMap<String,String>();       //数据采用的哈希表结构
            //给map中添加元素
            map.put("name", "wangyuhong");
            map.put("age", "44");


            Sender sender = new Sender("633c548b-6485-435a-bdd5-231763dfbb70");//注册登录开发平台网站获取到的appSecret
            Result result = sender.getToken(105294315 ,   "729b1dced86993213d79b600a180c1c2");//注册登录开发平台网站获取到的appId和appKey
            sender.setAuthToken(result. getAuthToken());
            Message singleMessage = new Message.Builder()
                    //该测试手机设备订阅推送所得的regid，且已添加为测试设备

                    .regId("16074818390129431589891")

                    .notifyType(3)
                    .title("try_title")
                    .content("try-content")
                    .timeToLive(1000)
                    .skipType(1)
    //                .skipType(3)
                    .skipContent("http://www.vivo.com")
                    .networkType(-1)
                    .requestId("1234567890123456")

                    .pushMode(1)


                    .clientCustomMap(map)


                    .build();
            Result resultMessage = sender.sendSingle(singleMessage);
            logger.info(resultMessage);
        } catch (Exception e) {
            e.printStackTrace();
        }*/

//        vivo_push.send_message_vivo_to_regid("16074818390129431589891","全局佈防2",
//                "[" + "8612345678" + ":" + "|3400 00 000]","8612345678","|3400 00 000]");
        vivo_push.send_message_vivo_to_regid_offiial_edition("16074818390129431589891","全局佈防66",
                "[" + "8612345678" + ":" + "|3400 00 000]","8612345678","|3400 00 000]");

    }

    @Test
    public void test2()  throws Exception {
        System.out.println("main函数开始执行");
        ExecutorService executor = Executors.newFixedThreadPool(2);
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(new Supplier<Integer>() {
            @Override
            public Integer get() {
                System.out.println("===task start===");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("===task finish===");
                return 3;
            }
        }, executor);
        future.thenAccept(e -> System.out.println(e));
        System.out.println("main函数执行结束");

    }

    @Test
    public void whenComplete() throws Exception {
        CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
            }
            if(new Random().nextInt()%2>=0) {
                int i = 12/0;
            }
            System.out.println("run end ...");
        });

        future.whenComplete(new BiConsumer<Void, Throwable>() {
            @Override
            public void accept(Void t, Throwable action) {
                System.out.println("执行完成！");
            }

        });
        future.exceptionally(new Function<Throwable, Void>() {
            @Override
            public Void apply(Throwable t) {
                System.out.println("执行失败！"+t.getMessage());
                return null;
            }
        });

        TimeUnit.SECONDS.sleep(2);
    }
}
